/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cognition.util.j2me;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Writes string output to console.
 * @author richard
 */
public class LoggerConsole extends Logger{

    private static ByteArrayOutputStream  _os =
            new ByteArrayOutputStream(80);
    private static final byte[] _sep = {':', ':'};

    public LoggerConsole(){
        super("CONSOLE");
    }
    public void log(int level, String name, String tag, Object msg) {
        try {
            _os.reset();
            _os.write(name.getBytes());
            _os.write(_sep);
            _os.write(SystemLogger.LOG_LEVELS[level].getBytes());
            _os.write(_sep);
            _os.write(tag.getBytes());
            _os.write(_sep);
            _os.write(msg.toString().getBytes());

            switch (level) {
                case SystemLogger.LOG_LEVEL_CRITICAL:
                case SystemLogger.LOG_LEVEL_ERROR:
                    System.err.println(_os.toString());
                    break;
                default:
                    System.out.println(_os.toString());
            }
            
        } catch (IOException ex) {
            System.err.println("Unable to log to the console.");
            ex.printStackTrace();
        }
    }

}
